package net.gz01.wallet.web.controller.customer;

import com.jfinal.plugin.activerecord.Page;
import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.web.controller.BaseController;
import net.gz01.wallet.web.model.Notice;

import java.util.List;

public class NoticeController extends BaseController {
	
	public void index() {

		ZOSearchCondition sc = super.getSearchCondition();
		String pageNum = getPara("p");
		String type = getPara("type");
		if(type == null || "".equals(type)){
			setAttr("currentType","all");
			setAttr("reqPath","/customer/notice?p=");
		}else{
			setAttr("currentType",type);
			sc.setParameter("noticeType",type);
			setAttr("reqPath","/customer/notice?type="+type+"&p=");
		}

		if(pageNum == null || pageNum.equals(""))
			sc.page.setPageNum(1);
		else
			sc.page.setPageNum(Integer.parseInt(pageNum));
		sc.page.setNumPerPage(10);

		Page<Notice> noticePage = Notice.dao.search(sc);
		List<Notice> noticeType = Notice.dao.selectNoticeType();
		setAttr("noticeType",noticeType);
		setAttr("noticePage",noticePage);
		render("noticeList.html");
	}


	public void goNoticeContentPage() {
		String id = getPara("id");
		Notice notice = Notice.dao.findById(id);
		List<Notice> noticeType = Notice.dao.selectNoticeType();
		setAttr("noticeInfo",notice);
		setAttr("noticeType",noticeType);
		render("noticeDetail.html");
	}
	
}
